<template>
  <div :class="className" :style="{height:height,width:width}"></div>
</template>

<script>
  import echarts from 'echarts'

  require('echarts/theme/macarons') // echarts theme
  import {debounce} from '@/utils'

  const animationDuration = 6000

  export default {
    name:'bar-chart',
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '350px'
      }
    },
    data() {
      return {
        chart: null,
        panelIncome: {
          paymentincome: '',
          payoutincome: '',
          shouldincome: '',
          statisticaltime: ''
        }
      }
    },
    mounted() {
      this.panelIncome.paymentincome = 82
      this.panelIncome.payoutincome = 70
      this.panelIncome.shouldincome = 92
      this.panelIncome.statisticaltime = 100
      const income = []
      income.push(this.panelIncome.shouldincome, this.panelIncome.shouldincome, this.panelIncome.payoutincome)
      // this.initChart(income)
      this.__resizeHanlder = debounce(() => {
        if (this.chart) {
          this.chart.resize()
        }
      }, 100)
      window.addEventListener('resize', this.__resizeHanlder)
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      window.removeEventListener('resize', this.__resizeHanlder)
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart(income) {
        console.log(income)
        this.chart = echarts.init(this.$el, 'macarons')
        this.chart.setOption({

          grid: {
            top: '10%',
            left: '2%',
            right: '2%',
            containLabel: true
          },
          xAxis:  {
            type: 'value',
            splitLine: {
              show: false
            },
            splitArea: {
              show: false
            }
          },
          yAxis: {
            type: 'category',
            splitLine: {
              show: false
            },
            splitArea: {
              show: false
            },
            data: ['XX车场诱导屏','二环东路诱导屏','二环西路诱导屏','工业南路诱导屏','经十路诱导屏']
          },
          series: [
            {
              type: 'bar',
              stack: '总量',
              label: {
                normal: {
                  show: true,
                  position: 'insideRight'
                }
              },
              itemStyle: {
                normal: {
                  shadowBlur: 40,
                  shadowColor: 'rgba(40, 40, 40, 0.5)',
                }
              },
              data: [22, 39, 43, 54, 65]
            }

          ]
        })
      }
    }
  }
</script>
